<?php

namespace wing\lib;

class route{

    public $ctrl;

    public $action;

    public function __construct()
    {

        /**
         * 隐藏index.php
         * 获取url参数
         * 返回对应的控制器
         */
        dd($_SERVER); 
        if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/'){
            dd($this->getRoutePath($_SERVER['REQUEST_METHOD'],$_SERVER['REQUEST_URI']));
            $path = $_SERVER['REQUEST_URI'];
            explode('/',$path);

        } else {
            //默认
            $this->ctrl = 'index';
            $this->action = 'index';
        }  
    }

    public function getRoutePath($type,$url)
    {
        fi($url )
        $exp_url = explode('/',trim('/',$url));
        dd(trim($url,'/'));
        if(!empty($exp_url[0])){
            $url_a = $exp_url[0];
        }else{
            $url_a = trim($url,'/');
        }
        
        $route = require(APP.'/route/'.$url_a.'.php');
        return explode('@',$route[$type][$url]);
    }
}